package com.itheima.mm.controller;


import com.itheima.mm.dto.QuestionsDto;
import com.itheima.mm.dto.R;
import com.itheima.mm.pojo.Body;
import com.itheima.mm.pojo.PageResult;
import com.itheima.mm.pojo.Query;
import com.itheima.mm.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/questions")
public class QuestionController {

    @Autowired
    private QuestionsService questionsService;
    //6.1审核意见
     @GetMapping("/{id}/auditOpinions")
     public R auditOpinions(@PathVariable Integer id){
    return questionsService.selectOpinion(id);
     }
     //6.2出题记录
    @GetMapping("/{id}/setRecords")
    public R selectQuestions(@PathVariable Integer id){
        return questionsService.selectRecords(id);
    }

    //6.3基础题库列表
    @GetMapping
    public PageResult findAllQuestion(Integer page, Integer pagesize, String subjectID, String difficulty, String questionType, String tags,
                                      String province, String city, String keyword, String remarks, String shortName, String direction, String creatorID, String catalogID) {

        return questionsService.findAll(page, pagesize, subjectID, difficulty, questionType, tags,
                province, city, keyword, remarks, shortName, direction, creatorID, catalogID);
    }
//6.4根据id删除基础题库
    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable Integer id) {
        questionsService.deleteById(id);
        return new R(true);
    }
    //6.5添加基础题库
    @PostMapping
    public R addQestion(@RequestBody QuestionsDto questionsDto){
      return   questionsService.addQestion(questionsDto);
    }
    //6.5根据id查询基础题信息
    @GetMapping("/{id}")
    public QuestionsDto selectById(@PathVariable Integer id){
       return questionsService.selectById(id);
    }
    //6.6修改基础题库信息
    @PutMapping("/{id}")
    public R modify(@PathVariable Integer id,@RequestBody QuestionsDto questionsDto){
        questionsService.modifyById(id,questionsDto);
        return new R(true);
    }
    //todo 6.7批量导入题

    //6.8精选题库上下架
    @PostMapping("/chocie/{questionId}/{operationId}")
    public R modifyStatus(@PathVariable Integer questionId, @PathVariable Integer operationId){
       questionsService.mofifyStatus(questionId,operationId);
       return new R(true);
}
//6.9查询精品题库列表
   @GetMapping("/choice")
    public PageResult findAllBest(Integer page,Integer pagesize){
      return  questionsService.findAllBest(page,pagesize);
   }
  //todo 6.10 组题列表
@GetMapping("/randoms")
public PageResult pageList(@RequestBody Query query){
       return   questionsService.pageList(query);
}
    //todo 6.11 组题列表删除
@GetMapping("/randoms/{id}")
public R deletList(@PathVariable Integer id){
return null;
}

   //6.12加入或者移出精选
    @PatchMapping("/choice/{id}/{choiceState}")
    public R removeBest(@PathVariable Integer id ,@PathVariable Integer choiceState){
        questionsService.removeBest(id,choiceState);
        return new R(true);
    }
    //6.13试题审核
    @PostMapping("/ckeck/{id}")
    public R auditById(@PathVariable Integer id,@RequestBody Body body){
       return questionsService.auditById(id,body);
    }

}
